package com.fenghuajueli.module_host;

import android.os.Bundle;
import android.widget.FrameLayout;

import androidx.annotation.Nullable;
import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentPagerAdapter;

import com.alibaba.android.arouter.facade.annotation.Route;
import com.alibaba.android.arouter.launcher.ARouter;
import com.fenghuajueli.libbasecoreui.adapter.DefaultViewPagerAdapter;
import com.fenghuajueli.libbasecoreui.listener.OnListClickListener;
import com.fenghuajueli.module_user.mine.ComposeMineFragment;
import com.fenghuajueli.module_host.databinding.ActivityMainBinding;
import com.fenghuajueli.module_route.CommonRoute;
import com.fenghuajueli.module_route.HomeModuleRoute;

import net.lucode.hackware.magicindicator.buildins.commonnavigator.CommonNavigator;

import java.util.ArrayList;
import java.util.List;

/**
 * 2021.12.10之后根据运营需求将申请设备信息的权限放到主页来进行
 */
@Route(path = CommonRoute.COMMON_MAIN)
public class MainActivity extends BaseMainActivity {
    ActivityMainBinding binding;
    private Fragment homeFragment;
    private Fragment mineFragment;

    private BaseTabAdapter baseTabAdapter;
    private DefaultViewPagerAdapter defaultViewPagerAdapter;
    private List<Fragment> fragmentList;


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        binding = ActivityMainBinding.inflate(getLayoutInflater());
        setContentView(binding.getRoot());
        homeFragment = (Fragment) ARouter.getInstance().build(HomeModuleRoute.HOME_PAGE).withString("name", "我叫张三").navigation();
        //这里如果有用户系统接入 将mineFragment设置为用户系统模块的代码
        mineFragment = new ComposeMineFragment();
        //新包一般没有用户系统 用以下fragment更改或者自己写一个都行
//        mineFragment = NotUserModuleMineFragment.newInstance();

        fragmentList = new ArrayList<>();
        fragmentList.add(homeFragment);
        fragmentList.add(mineFragment);
        initAdapter();
    }


    private void initAdapter() {
        baseTabAdapter = new BaseTabAdapter(binding.magicIndicator, new String[]{"首页", "我的"});
        CommonNavigator commonNavigator = new CommonNavigator(this);
        commonNavigator.setAdapter(baseTabAdapter);
        commonNavigator.setAdjustMode(true);
        binding.magicIndicator.setNavigator(commonNavigator);
        baseTabAdapter.setOnListClickListener(new OnListClickListener<Integer>() {
            @Override
            public void itemClick(int position, Integer data) {
                binding.viewPager.setCurrentItem(position, false);
            }
        });
        defaultViewPagerAdapter = new DefaultViewPagerAdapter(getSupportFragmentManager(),
                fragmentList, FragmentPagerAdapter.BEHAVIOR_RESUME_ONLY_CURRENT_FRAGMENT);
        binding.viewPager.setAdapter(defaultViewPagerAdapter);
    }

    @Nullable
    @Override
    public FrameLayout adBannerView() {
        return binding.flBanner;
    }
}